﻿using common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MS_UI
{
    public partial class MyBtn : UserControl
    {
        private int width = 133;
        //默认带有一下两个参数
        //属性是否可见，默认true
        [Browsable(true)]
        //属性是否被修改后自动保存，默认是
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public int Widths
        {
            get { return width; }
            set { width = value; }
        }
        private int height = 48;

        public int Heights
        {
            get { return height; }
            set { height = value; Invalidate(); }
        }
        private int font = 9;

        public int Fonts
        {
            get
            {
                return font;
            }
            set
            {
                font = value;
                Invalidate();
            }

        }
        private int singles = 0;

        public int Singles
        {
            get
            {
                return singles;
            }
            set
            {
                singles = value;
                Invalidate();
            }
        }
        private Color colors = Color.FromArgb(255, 255, 255);

        public Color Colors
        {
            get
            {
                return colors;
            }
            set
            {
                colors = value;
                Invalidate();
            }
        }
        private string texts = "Button";

        public string Texts
        {
            get
            {
                return texts;
            }
            set
            {
                texts = value;
                Invalidate();
            }
        }
        private Cursor cs = Cursors.Hand;
        public Cursor Cs
        {
            get
            {
                return cs;
            }
            set
            {
                cs = value;
                Invalidate();
            }
        }
        private Color bg = Color.FromArgb(0, 117, 189);
        public Color BG
        {
            get
            {
                return bg;
            }
            set
            {
                bg = value;
                this.Refresh();
            }
        }
        public MyBtn()
        {
            InitializeComponent();
            this.Load += InitConfig();
        }
        //接受参数传递
        private EventHandler InitConfig()
        {
            return (s, e) =>
            {
                this.Width = Widths;
                this.Height = Heights;
                button1.Text = Texts;
                button1.Font = new Font(button1.Font.FontFamily, Fonts, button1.Font.Style);
                button1.FlatStyle = singles == 0 ? FlatStyle.Flat : FlatStyle.Popup;
                button1.ForeColor = Colors;
                button1.BackColor = BG;
            };
        }




        public event EventHandler ClickHand;
        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            button1.Cursor = cs;
            //(s) => { } 是一个空的回调方法，表示在异步操作完成后不做任何操作。
            //null 是传递给委托的可选参数，这里未使用。
            //BeginInvoke 方法是异步执行的。
            //\它会将 OverHand 委托异步调度到关联的控件的 UI 线程上执行。
            //OverHand.BeginInvoke(this,e,(s) => { },null);
            //OverHand.Invoke(this, e);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ClickHand?.BeginInvoke(this, e, ob => { }, null);
        }

        private void MyBtn_Load(object sender, EventArgs e)
        {

        }
    }
}
